﻿<Serializable()> _
Public Class ServerFolder
    Sub New()
        'do nothing
    End Sub
    Sub New(ByVal thispath As String, ByVal thisname As String, ByVal ParentID As Integer)
        Dim Dir As New DirectoryInfo(Path.Combine(thispath, thisname))
        For Each ThisDir In Dir.GetDirectories
            SubFolders.Add(New ServerFolder(Dir.FullName, ThisDir.Name, Dir.GetHashCode))
        Next
        For Each ThisFile In Dir.GetFiles
            'exclude system,hidden and temp files
            If Not ThisFile.Attributes = FileAttributes.Hidden And _
               Not ThisFile.Attributes = FileAttributes.System And _
               Not ThisFile.Attributes = FileAttributes.Temporary And _
               Not ThisFile.Name.ToLower = "thumbs.db" Then
                Files.Add(New ServerFile(ThisFile))
            End If
        Next
        _ParentFolderID = ParentID
        _FolderID = Dir.GetHashCode
        _FolderName = Dir.Name
        _OrigFolderName = Dir.Name
        _FullPath = thispath
        _URLPath = thispath.Replace(FileTree.PathName, "").Replace("\", "/")
        _CreationDate = Dir.CreationTime
        _ModifiedDate = Dir.LastWriteTime
        'For Each item In dir.GetDirectories
        '_SubFolders.Add(New ServerFolder(item, _FolderID))
        'Next
    End Sub
    Private _ParentFolderID As Integer
    Public Property ParentFolderID() As Integer
        Get
            Return _ParentFolderID
        End Get
        Set(ByVal value As Integer)
            _ParentFolderID = value
        End Set
    End Property
    Private _FolderID As Integer
    Private Property FolderID() As Integer
        Get
            Return _FolderID
        End Get
        Set(ByVal value As Integer)
            _FolderID = value
        End Set
    End Property
    Private _FolderName As String
    Public Property FolderName() As String
        Get
            Return _FolderName
        End Get
        Set(ByVal value As String)
            _FolderName = value
        End Set
    End Property
    Private _OrigFolderName As String
    Public Property OrigFolderName() As String
        Get
            Return _OrigFolderName
        End Get
        Set(ByVal value As String)
            _OrigFolderName = value
        End Set
    End Property
    Private _FullPath As String
    Public Property FullPath() As String
        Get
            Return _FullPath
        End Get
        Set(ByVal value As String)
            _FullPath = value
        End Set
    End Property
    Private _URLPath As String
    Public Property URLPath() As String
        Get
            Return _URLPath
        End Get
        Set(ByVal value As String)
            _URLPath = value
        End Set
    End Property
    Private _CreationDate As Date
    Public Property CreationDate() As Date
        Get
            Return _CreationDate
        End Get
        Set(ByVal value As Date)
            _CreationDate = value
        End Set
    End Property
    Private _ModifiedDate As Date
    Public Property ModifiedDate() As Date
        Get
            Return _ModifiedDate
        End Get
        Set(ByVal value As Date)
            _ModifiedDate = value
        End Set
    End Property
    Private _SubFolders As List(Of ServerFolder)
    Public Property SubFolders() As List(Of ServerFolder)
        Get
            If _SubFolders Is Nothing Then
                _SubFolders = New List(Of ServerFolder)()
            End If
            Return _SubFolders
        End Get
        Set(ByVal value As List(Of ServerFolder))
            _SubFolders = value
        End Set
    End Property
    Private _Files As List(Of ServerFile)
    Public Property Files() As List(Of ServerFile)
        Get
            If _Files Is Nothing Then
                _Files = New List(Of ServerFile)
            End If
            Return _Files
        End Get
        Set(ByVal value As List(Of ServerFile))
            _Files = value
        End Set
    End Property
End Class